﻿using DeMeng.Services.BaseServices;
using System;
using System.Collections.Generic;
using System.Text;
using DeMeng.Models.Models.UserInfo;
using DeMeng.Repository;
using System.Threading.Tasks;
using DeMeng.Models.ViewModels.UserInfo;
using DeMeng.Models.Enums.UserInfo;
using DeMeng.Models;
using DeMeng.Common.Utilities;
using System.Linq;
using DeMeng.Repository.Sms;
using DeMeng.Models.Enums.Sms;
using DeMeng.Models.Models.Sms;
using Newtonsoft.Json;
using DeMeng.Common.HttpContextUser;
using DeMeng.Common.Mappers;
using DeMeng.Common.Jwt;
using DeMeng.Models.PageModel;
using SqlSugar;
using DeMeng.Common.Config;
using AutoMapper;
using Senparc.Weixin;
using Senparc.Weixin.WxOpen.Containers;
using DeMeng.Models.Models;
using DeMeng.Models.Models.Poster;

namespace DeMeng.Services.Domain
{
    public class PosterServices : BaseServices<PosterEntity>, IPosterServices
    {
        private readonly IPosterRepository _posterRepository;
 
        private readonly IAspNetUser _aspNetUser;
        
        object obj = new object { };
        public PosterServices(IPosterRepository dal, ISmsRepository smsRepository, IAspNetUser aspNetUser )
        {
            base.BaseDal = dal;

            _posterRepository = dal;
                 _aspNetUser = aspNetUser;
            
        } 
        


        #region CURD
        public async Task<PageResultModel<PosterEntity>> FindList(PosterListQueryModel query)
        {
            query.WhereLambda = Expressionable.Create<PosterEntity>().
               //And(s => !s.IsDeleted).
               AndIF(!string.IsNullOrWhiteSpace(query.GameName), s => s.GameName.Contains(query.GameName) ).
            

                
               ToExpression();
            query.OrderString = " ShowEndTime desc ,id desc ";
            return await _posterRepository.Pages<PosterEntity>(query);
        }

        /// <summary>
        /// 保存修改客户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task< bool> Save(PosterEntity model)
        { 

           
                
                model.Image = string.IsNullOrWhiteSpace(model.Image) ? "" : model.Image.Replace(WebConfig.WebSiteUrl, string.Empty);
                if (model.ID == 0)
                { //保存
                   
                    return await _posterRepository.Add(model) > 0;
                }
                else
                { //修改 
                    return await  _posterRepository.Update(model);
                }
            
        }
         
        
        #endregion
          
  

        

    }

}
